<?php

namespace app\admin\model;

use think\Model;

class Coupon extends Model {

    // 表名
    protected $name = 'coupon';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [
        'receive_type_text',
        'status_text'
    ];

    public function getStatusTypeList() {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '10' => __('Status 10')];
    }

    public function getReceiveTypeList() {
        return ['0' => __('Receive_type 0'), '1' => __('Receive_type 1'), '2' => __('Receive_type 2')];
    }
    
    public function getRangeList() {
        return ['0' => __('Range 0'), '1' => __('Range 1'), '2' => __('Range 2')];
    }
    
    public function getExpiryTypeList() {
        return ['0' => __('Expiry_type 0'), '1' => __('Expiry_type 1')];
    }

    public function getStatusTextAttr($value, $data) {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : 0);
        $list = $this->getStatusTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getReceiveTypeTextAttr($value, $data) {
        $value = $value ? $value : (isset($data['receive_type']) ? $data['receive_type'] : '');
        $list = $this->getReceiveTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

}
